﻿using System;
using System.Data;
using Token.Piker.BLL;
using Token.Piker.Common;

namespace Token.Piker.Web.Admin.Photo
{
    public partial class Show : System.Web.UI.Page
    {
        PhotoBLL bll = new PhotoBLL();
        static Model.Photo photo;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string ID = Request["ID"];

                if (string.IsNullOrEmpty(ID))
                {
                    MessageBox.Show(this.Page, "非法的参数");
                    return;
                }

                photo = bll.GetModel(int.Parse(ID));
                ltrID.Text = photo.ID.ToString();
                ltrAlbum.Text = photo.Album.ToString();
                ltrCity.Text = photo.City;
                ltrDescrip.Text = photo.Descrip;
                ltrExifVersionExif.Text = photo.ExifVersionExif;
                ltrExposureBiasValue.Text = photo.ExposureBiasValue;
                ltrExposureProgram.Text = photo.ExposureProgram;
                ltrExposureTime.Text = photo.ExposureTime;
                ltrFNumber.Text = photo.FNumber;
                ltrISO.Text = photo.ISO;
                ltrLightsource.Text = photo.Lightsource;
                ltrLikeCount.Text = photo.LikeCount.ToString();
                ltrMake.Text = photo.Make;
                ltrMeteringMode.Text = photo.MeteringMode;
                ltrModel.Text = photo.Model;
                ltrPhotoName.Text = photo.PhotoName;
                ltrPosition.Text = photo.Position;
                ltrProvince.Text = photo.Province;
                ltrSoftware.Text = photo.Software;
                ltrUploadTime.Text = photo.UploadTime.ToString();
                ltrUserID.Text = photo.UserID.ToString();

                linkSourceUrl.NavigateUrl = photo.SourceUrl;
                linkCompressUrl_1.NavigateUrl = photo.CompressUrl_1;
                linkCompressUrl_2.NavigateUrl = photo.CompressUrl_2;
                linkCompressUrl_3.NavigateUrl = photo.CompressUrl_3;
                linkCompressUrl_4.NavigateUrl = photo.CompressUrl_4;

                //显示图片标签信息
                string contentTag = string.Empty;
                string styleTag = string.Empty;

                DataSet ds = (new PhotoTagBLL()).GetPhotoTagsByID(photo.ID);
                DataTable dt = ds.Tables[0];

                for (int i = 0; i < dt.Rows.Count;i++ )
                {
                    DataRow dr = dt.Rows[i];

                    if (Convert.ToInt32(dr["Flag"]) == 0)
                    {
                        contentTag += dr["TagName"].ToString() + " ";
                    }
                    else
                    {
                        styleTag += dr["TagName"].ToString() + " ";
                    }
                }

                ltrContentTag.Text = contentTag;
                ltrStyleTag.Text = styleTag;

                lkbFlag.Text = photo.Flag == 0 ? "正常" : "已删除";
            }
        }

        protected void lkbFlag_Click(object sender, EventArgs e)
        {
            //更改图片状态
            if (lkbFlag.Text == "正常")
            {
                photo.Flag = 1;
            }
            else
            {
                photo.Flag = 0;
            }

            if (bll.Update(photo) == true)
            {
                lkbFlag.Text = photo.Flag == 0 ? "正常" : "已删除";
            }
        }
    }
}